<layout name="bootlayout" />
<script src="__JS__jquery.form.js"></script>
<style>
    .set_div { width: 100%; border-top: 2px solid #ddd; padding: 10px; }
</style>
<div style="margin:10px;">
    <div style="width:100%;">
        栏目管理：
    </div>
    <div style="margin:10px 0 0 50px;">
        <table class="table">
            <thead>
                <tr>
                    <th>排序</th>
                    <th>cate_id</th>
                    <th> 名称</th>
                    <th> 模型</th>
                    <th>描述</th>
                    <th> 操作</th>
                </tr>
            </thead>
            <?php 
         	 $sum=0;
            function str_num(){
				 global $sum;
				$str="";
            	for ($i=0;$i<$sum;$i++){
            		$str=$str."&nbsp;&nbsp;&nbsp;&nbsp;";
            	}
            	if($sum!=0){
            		$str=$str."|—";
            	}
            	return $str;
 
            }
            
            function cate_str($data){
    			      global $sum;
  				foreach ($data as $vo){
				?>
				     <tr>
                            <td><input size="2" name="listorder[{$vo.id}]"  value="{$vo.listorder}"/></td>
                            <td>{$vo.id}</td>
                            <td><?php echo str_num();?>{$vo.name}</td>
                            <td>{$vo.model_name}</td>
                            <td>{$vo.description}</td>
                            <td>
                                <button type="button" class="btn btn-default" data-toggle="modal" data-target="#myModal" 
onclick="model_up('{$vo.id}');">
                                    修改
                                </button>
                                <button type="button" class="btn btn-default" onclick="cateDe({$vo.id});">
                                    删除
                                </button>
                            </td>
                        </tr>
				<?php 
				if(is_array($vo['son']))
					{
						$sum++;
						cate_str($vo['son']);
						$sum--;
					}
  				}
            }
            ?>
            <tbody>
            	<form action="/admin/WebSet/listorderCate" method="post" id="listorder">
                  <?php cate_str($data);?>
                  </form>
            </tbody>
        </table>
        <div class="btn-group set_div">
            <button type="button" class="btn btn-default" class="btn btn-primary btn-lg" data-toggle="modal"  onclick="listorderCate()"> 排序</button>
             <button type="button" class="btn btn-default" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal" onclick="model_add()">
                新增
            </button>
        </div>
        <!--新增模型sart-->
        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                            &times;
                        </button>
                        <h4 class="modal-title" id="myModalLabel">新增/修改栏目</h4>
                    </div>
                    <div class="modal-body" style="overflow:hidden;">
                        <form action="/admin/WebSet/cate" method="post" id="model_set">
                            <input type="hidden" id="id" name="id"/>
							<input type="hidden" id="thumb" name="thumb"/>
                            <div style="float:left;width:50%;">
                                <div class="form-group">
                                    <label for="exampleInputEmail1">
                                        名称
                                    </label>
                                    <input type="text" class="form-control" id="name" name="name">
                                </div>
                                <div style="margin:0px 0px 10px 0px;">
                                    模型：
                                    <select name="model_id" id="model_id">
                                        <foreach name="modelinfo" item="vo">
                                            <option value="{$vo.id}">{$vo.name}</option>
                                        </foreach>
                                    </select><br>
                                    父栏目：
                                    <select name="pid" id="pid">
                                    <option value="0">..请选择..</option>
                                      <?php 
									          $sum=0;
									            function cate_str1($data){
									    			      global $sum;
									  				foreach ($data as $vo){
													?>
                                            <option value="{$vo.id}"  ><?php echo str_num();?>{$vo.name}</option>
                                        	<?php 
														if(is_array($vo['son']))
															{
																$sum++;
																cate_str1($vo['son']);
																$sum--;
															}
										  				}
										            }
										            ?>    
										 		 <?php cate_str1($data);?>
									 </select>
                                </div>
                                <div class="form-group">
                                    <label for="exampleInputEmail1">
                                        描述
                                    </label>
                                    <input type="text" class="form-control" id="description" name="description">
                                </div>
                                <div class="form-group">
                                    <label for="exampleInputEmail1">
                                        SEO标题
                                    </label>
                                    <input type="text" class="form-control" id="seo_title" name="seo_title">
                                </div>
                                <div class="form-group">
                                    <label for="exampleInputEmail1">
                                        SEO关键字
                                    </label>
                                    <input type="text" class="form-control" id="seo_key" name="seo_key">
                                </div>
                                <div class="form-group">
                                    <label for="exampleInputEmail1">
                                        SEO内容
                                    </label>
                                    <input type="text" class="form-control" id="seo_description" name="seo_description">
                                </div>
                            </div>
                        </form>
                       <!-- 						缩略图上传 -->
						<style>
	                     .upload-img-thumb{width:100%;position: relative;}
	                     .upload-img-thumb1{position: absolute;left:70%;border:1px solid #eee;border-top:2px solid #eec;-webkit-border-radius: 6px;border-radius: 6px;}
						.upload-img-thumb2{margin: 0 auto; width: 167px; margin-bottom: 20px;}
	                     #img_preview{width: 167px; height: 125px;}
	                     #file_upload{margin:0 auto;}
						</style>
							<div class="upload-img-thumb"></div>
							<div class="upload-img-thumb1">
							<div class="upload-img-thumb2">
								<img  <?php if($data['thumb']){?>src="<?=$data['thumb'] ?>" <?php }else{?> src="__IMG__images.jpg" <?php }?>  id="img_preview">
							</div>
							<div style="width: 100%;">
									<div class="col-lg-6" style="width:100%;">
										<div class="input-group" >
													<input id="file_upload" name="thumb" type="file" multiple="true">
										</div>
										<div style="width:90px;margin:0 auto;">
										<a href="javascript:$('#file_upload').uploadify('cancel')" class="button" >删除</a>
										<a href="javascript:$('#file_upload').uploadify('upload')" class="button" style="">上传</a>
										</div>
									</div>
							</div>
							</div>
								<script type="text/javascript">
								    $(function() {
								        $('#file_upload').uploadify({
								       	 'auto'     : false,
								            'swf'      : '/Public/js/uploadify.swf',    //指定上传控件的主体文件
								            'uploader' : '/admin/logining/imgUpload',    //指定服务器端上传处理文件
								            'onUploadSuccess' : function(file, data, response) {
								                $("#img_preview").attr("src",data);
								 	 			$("#thumb").val(data);
								            }
								        });
								    });
								</script>
<!-- 							end 缩略图上传 -->
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">
                            Close
                        </button>
                        <button type="button" class="btn btn-primary" onclick="model_save();">
                            保存
                        </button>
                    </div>
                </div>
            </div>
        </div>
        <!--新增模型end-->
    </div>
</div>
<script>
    function model_add(){
        $("#name").val("");
        $("#id").val("");
        $("#table").val("");
        $("#description").val("");
		 $("#seo_title").val("");
        $("#seo_key").val("");
        $("#thumb").val("");
		 $("#seo_description").val("");
		 $("#img_preview").attr("src","/Public/images/images.jpg");
    }
    
    function model_up(id){
        $.post("/admin/WebSet/cateOne",{id:id},function(data){
       	 $("#name").val(data.name);
         $("#id").val(data.id);
         $("#table").val(data.table);
         $("#seo_title").val(data.seo_title);
         $("#seo_key").val(data.seo_key);
         $("#thumb").val(data.thumb);
         $("#seo_description").val(data.seo_description);
         $("#description").val(data.description);
 		$("#img_preview").attr("src",data.thumb);
 		$("#pid option[value='"+data.pid+"']").attr("selected", true); 
 		$("#model_id option[value='"+data.model_id+"']").attr("selected", true); 
 		if(!thumb){
 			 $("#img_preview").attr("src","/Public/images/images.jpg");
 		}
            });
       
    }
    
    function model_save(){
        $("#model_set").submit();
    }
	//删除栏目
function cateDe(id){
		  if(confirm("确定删除?")){
			  $.post("/admin/WebSet/cateDe",{id:id},function(data){
		        	 location.reload();
		             });     
			  };
}
//排序
function listorderCate(){
	$("#listorder").submit();
	  }
	
</script>
